package com.spark.concurrency.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

public class CallableTest {
    public static void main(String[] args) throws Exception {
        MyCallable callable = new MyCallable();
        // 定义返回结果
        FutureTask<String> result = new FutureTask<>(callable);
        // 执行程序
        new Thread(result).start();
        // 输出返回结果
        System.out.println(result.get());
    }
}

class MyCallable implements Callable<String> {
    @Override
    public String call() {
        System.out.println("Callable");
        return "Success";
    }
}
/*以上程序执行结果如下：
Callable
Success*/